package com.lqh.studyproject.agentmodel.dynamicproxy;

import sun.misc.ProxyGenerator;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Proxy;

/**
 * @ClassName JDKProxyTest
 * @Description studyproject
 * @Author bgy-lqh
 * @Date 2020/6/19 17:04
 * @Version jdkproxy测试类
 **/
public class JDKProxyTest {
    public static void main(String[] args) {
        JDKProxy jdkProxy=new JDKProxy(new JDKProxyTarget());
        ProxyInterface proxyInterface=(ProxyInterface) jdkProxy.instanceProxy();
        System.out.println(proxyInterface.getClass());
        proxyInterface.targetMethod();

        byte[] bytes = ProxyGenerator.generateProxyClass("$Proxy0", new Class[]{ProxyInterface.class});
        FileOutputStream outputStream = null;
        try {
            outputStream = new FileOutputStream("E:\\$Proxy0.class");
            outputStream.write(bytes);
            outputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}